<template>
    <a-card :bordered="false">
        <!-- 查询区域 -->
        <div class="table-page-search-wrapper">
            <a-form layout="inline" @keyup.enter.native="searchQuery">
                <a-row :gutter="24">
                    <a-col :lg="7" :md="8" :sm="24" :xl="6">
                        <a-form-item label="车牌号">
                            <j-input v-model="queryParam.plateNo" placeholder="请输入车牌号"></j-input>
                        </a-form-item>
                    </a-col>
                    <a-col :lg="7" :md="8" :sm="24" :xl="6">
                        <a-form-item label="司机姓名">
                            <a-input v-model="queryParam.driverName"
                                placeholder="请输入司机姓名"></a-input>
                        </a-form-item>
                    </a-col>
                    <template v-if="toggleSearchStatus">
                        <a-col :lg="7" :md="8" :sm="24" :xl="6">
                            <a-form-item label="手机号">
                                <a-input v-model="queryParam.phoneNum"
                                    placeholder="请输入手机号"></a-input>
                            </a-form-item>
                        </a-col>
                        <a-col :lg="7" :md="8" :sm="24" :xl="6">
                            <a-form-item label="车队">
                                <a-input v-model="queryParam.fleet" placeholder="请输入车队"></a-input>
                            </a-form-item>
                        </a-col>
                        <a-col :lg="7" :md="8" :sm="24" :xl="6">
                            <a-form-item label="检验人员姓名">
                                <a-input v-model="queryParam.surveyorName"
                                    placeholder="请输入检验人员姓名"></a-input>
                            </a-form-item>
                        </a-col>
                        <a-col :lg="11" :md="12" :sm="24" :xl="10">
                            <a-form-item label="上次清洗时间">
                                <j-date v-model="queryParam.lastTimeCleaningDate_begin"
                                    :show-time="true" class="query-group-cust"
                                    date-format="YYYY-MM-DD HH:mm:ss"
                                    placeholder="请选择开始时间"></j-date>
                                <span class="query-group-split-cust"></span>
                                <j-date v-model="queryParam.lastTimeCleaningDate_end"
                                    :show-time="true" class="query-group-cust"
                                    date-format="YYYY-MM-DD HH:mm:ss"
                                    placeholder="请选择结束时间"></j-date>
                            </a-form-item>
                        </a-col>
                        <a-col :lg="11" :md="12" :sm="24" :xl="10">
                            <a-form-item label="入场时间">
                                <j-date v-model="queryParam.entryTime_begin" :show-time="true"
                                    class="query-group-cust" date-format="YYYY-MM-DD HH:mm:ss"
                                    placeholder="请选择开始时间"></j-date>
                                <span class="query-group-split-cust"></span>
                                <j-date v-model="queryParam.entryTime_end" :show-time="true"
                                    class="query-group-cust" date-format="YYYY-MM-DD HH:mm:ss"
                                    placeholder="请选择结束时间"></j-date>
                            </a-form-item>
                        </a-col>
                        <a-col :lg="11" :md="12" :sm="24" :xl="10">
                            <a-form-item label="出场时间">
                                <j-date v-model="queryParam.exitTime_begin" :show-time="true"
                                    class="query-group-cust" date-format="YYYY-MM-DD HH:mm:ss"
                                    placeholder="请选择开始时间"></j-date>
                                <span class="query-group-split-cust"></span>
                                <j-date v-model="queryParam.exitTime_end" :show-time="true"
                                    class="query-group-cust" date-format="YYYY-MM-DD HH:mm:ss"
                                    placeholder="请选择结束时间"></j-date>
                            </a-form-item>
                        </a-col>
                        <a-col :lg="11" :md="12" :sm="24" :xl="10">
                            <a-form-item label="审核时间">
                                <j-date v-model="queryParam.auditDate_begin" :show-time="true"
                                    class="query-group-cust" date-format="YYYY-MM-DD HH:mm:ss"
                                    placeholder="请选择开始时间"></j-date>
                                <span class="query-group-split-cust"></span>
                                <j-date v-model="queryParam.auditDate_end" :show-time="true"
                                    class="query-group-cust" date-format="YYYY-MM-DD HH:mm:ss"
                                    placeholder="请选择结束时间"></j-date>
                            </a-form-item>
                        </a-col>
                        <a-col :lg="11" :md="12" :sm="24" :xl="10">
                            <a-form-item label="检验时间">
                                <j-date v-model="queryParam.surveyorDate_begin" :show-time="true"
                                    class="query-group-cust" date-format="YYYY-MM-DD HH:mm:ss"
                                    placeholder="请选择开始时间"></j-date>
                                <span class="query-group-split-cust"></span>
                                <j-date v-model="queryParam.surveyorDate_end" :show-time="true"
                                    class="query-group-cust" date-format="YYYY-MM-DD HH:mm:ss"
                                    placeholder="请选择结束时间"></j-date>
                            </a-form-item>
                        </a-col>
                    </template>
                    <a-col :lg="7" :md="8" :sm="24" :xl="6">
                        <span class="table-page-search-submitButtons"
                            style="float: left;overflow: hidden;">
                            <a-button icon="search" type="primary"
                                @click="searchQuery">查询</a-button>
                            <a-button icon="reload" style="margin-left: 8px" type="primary"
                                @click="searchReset">重置</a-button>
                            <a style="margin-left: 8px" @click="handleToggleSearch">
                                {{ toggleSearchStatus ? '收起' : '展开' }}
                                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
                            </a>
                        </span>
                    </a-col>
                </a-row>
            </a-form>
        </div>
        <!-- 查询区域-END -->

        <!-- 操作按钮区域 -->
        <div class="table-operator">
            <a-button icon="download" type="primary" @click="handleExportXls('罐车登记表')">导出</a-button>
        </div>

        <!-- table区域-begin -->
        <div>
            <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
                <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a
                    style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
                <a style="margin-left: 24px" @click="onClearSelected">清空</a>
            </div>

            <a-table ref="table" :columns="columns" :dataSource="dataSource" :loading="loading"
                :pagination="ipagination"
                :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
                :scroll="{x:true}" bordered class="j-table-force-nowrap" rowKey="id" size="middle"
                @change="handleTableChange">

                <span slot="auditStatus" slot-scope="text">
                    <a-tag v-if="text==1" color="geekblue">新登记</a-tag>
                    <a-tag v-if="text==2" color="green">入场前检验通过</a-tag>
                    <a-tag v-if="text==3" color="volcano">三载审核驳回</a-tag>
                    <a-tag v-if="text==4" color="orange">三载审核待确认</a-tag>
                    <a-tag v-if="text==5" color="green">品质经理通过</a-tag>
                    <a-tag v-if="text==5" color="orange">业务经理未通过</a-tag>
                    <a-tag v-if="text==6" color="orange">品质经理未通过</a-tag>
                    <a-tag v-if="text==6" color="green">业务经理通过</a-tag>
                    <a-tag v-if="text==7" color="green">品质经理通过</a-tag>
                    <a-tag v-if="text==7" color="green">业务经理通过</a-tag>
                    <a-tag v-if="text==8" color="green">验罐合格</a-tag>
                    <a-tag v-if="text==9" color="volcano">验罐不合格</a-tag>
                    <a-tag v-if="text==10" color="orange">验罐待确定</a-tag>
                    <a-tag v-if="text==11" color="green">已铅封</a-tag>
                    <a-tag v-if="text==12" color="volcano">已废弃</a-tag>
                    <a-tag v-if="text==13" color="volcano">已过期</a-tag>
                    <a-tag v-if="text==14" color="#444">黑名单</a-tag>
                    <a-tag v-if="text==15" color="green">三载通过待拍照</a-tag>
                    <a-tag v-if="text==16" color="green">已检斤完成</a-tag>
                </span>
                <template slot="htmlSlot" slot-scope="text">
                    <div v-html="text"></div>
                </template>
                <template slot="imgSlot" slot-scope="text">
                    <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
                    <viewer :options="options" v-else class="viewer" ref="viewer">
                        <img src="../../assets/yulan.png" :data-source="getImgView(text)"
                            height="25px" alt=""
                            style="max-width: 80px; font-size: 12px; font-style: italic" />
                    </viewer>
                </template>
                <template slot="fileSlot" slot-scope="text">
                    <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
                    <a-button v-else :ghost="true" icon="download" size="small" type="primary"
                        @click="downloadFile(text)">
                        下载
                    </a-button>
                </template>
                <span slot="action" slot-scope="text, record">
                    <a @click="showModal(record)" v-if="record.auditStatus==11">检斤</a>
                    <a-divider type="vertical" v-if="record.auditStatus==11" />
                    <a @click="handleDetail(record)">详情</a>
                </span>
            </a-table>
        </div>

        <tanker-registration-modal ref="modalForm" @ok="modalFormOk"></tanker-registration-modal>

        <a-modal title="检斤" :visible="visible" :confirm-loading="confirmLoading" @ok="handleOk"
            @cancel="handleCancel">
            <div style="margin-left: 10%;">
                <p>
                    <span style="margin-right: 24px;">车牌号: </span>
                    <span v-if="tankerRegistration">{{ tankerRegistration.plateNo }}</span>
                </p>
                <p>
                    <span style="margin-right: 24px;">司机姓名: </span>
                    <span v-if="tankerRegistration">{{ tankerRegistration.driverName }}</span>
                </p>
                <p>
                    <span style="margin-right: 24px;">手机号: </span>
                    <span v-if="tankerRegistration">{{ tankerRegistration.phoneNum }}</span>
                </p>
            </div>
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="重量(吨)">
                <a-input v-model="weight" placeholder="请输入重量(吨)"></a-input>
            </a-form-item>
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="收货企业名称">
                <a-input v-model="receiptCompany" placeholder="请输入收货企业名称"></a-input>
            </a-form-item>

        </a-modal>

    </a-card>
</template>

<script>

import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import TankerRegistrationModal from './modules/TankerRegistrationModal'
import { postAction, putAction } from "@api/manage";

export default {
    name: 'TankerRegistrationList',
    mixins: [JeecgListMixin, mixinDevice],
    components: {
        TankerRegistrationModal,
    },
    data() {
        return {
            ModalText: 'Content of the modal',
            visible: false,
            confirmLoading: false,
            labelCol: {
                xs: { span: 24 },
                sm: { span: 5 },
            },
            wrapperCol: {
                xs: { span: 24 },
                sm: { span: 16 },
            },
            form: {},
            labelVisible: false,
            labelLoading: false,
            description: '罐车登记表管理页面',
            // 表头
            columns: [
                {
                    title: '#',
                    dataIndex: '',
                    key: 'rowIndex',
                    width: 60,
                    align: "center",
                    customRender: function (t, r, index) {
                        return parseInt(index) + 1;
                    }
                },
                {
                    title: '审核状态',
                    align: "center",
                    dataIndex: 'auditStatus',
                    scopedSlots: { customRender: 'auditStatus' },
                },
                {
                    title: '入场状态',
                    align: "center",
                    dataIndex: 'entryStatus_dictText'
                },
                {
                    title: '重量(吨)',
                    align: "center",
                    dataIndex: 'weight'
                },
                {
                    title: '收货企业名称',
                    align: "center",
                    dataIndex: 'receiptCompany'
                },
                {
                    title: '车牌号',
                    align: "center",
                    dataIndex: 'plateNo'
                },
                {
                    title: '挂车号',
                    align: "center",
                    dataIndex: 'trailerNo'
                },
                {
                    title: '司机姓名',
                    align: "center",
                    dataIndex: 'driverName'
                },
                {
                    title: '手机号',
                    align: "center",
                    dataIndex: 'phoneNum'
                },
                {
                    title: '产品种类',
                    align: "center",
                    dataIndex: 'productionType'
                },
                {
                    title: '车队',
                    align: "center",
                    dataIndex: 'fleet'
                },
                {
                    title: '前一载卸货公司',
                    align: "center",
                    dataIndex: 'lastTimeUnloadingCompanyName1'
                },
                {
                    title: '前一载卸车货品名称',
                    align: "center",
                    dataIndex: 'lastTimeUnloadingGoodsName1'
                },
                {
                    title: '前一载卸货日期',
                    align: "center",
                    dataIndex: 'lastTimeUnloadingDate1',
                    customRender: function (t, r, index) {
                        return t ? t.substring(0, 10) : "";
                    }
                },
                {
                    title: '前二载卸货公司',
                    align: "center",
                    dataIndex: 'lastTimeUnloadingCompanyName2'
                },
                {
                    title: '前二载卸车货品名称',
                    align: "center",
                    dataIndex: 'lastTimeUnloadingGoodsName2'
                },
                {
                    title: '前二载卸货日期',
                    align: "center",
                    dataIndex: 'lastTimeUnloadingDate2',
                    customRender: function (t, r, index) {
                        return t ? t.substring(0, 10) : "";
                    }
                },
                {
                    title: '前三载卸货公司',
                    align: "center",
                    dataIndex: 'lastTimeUnloadingCompanyName3'
                },
                {
                    title: '前三载卸车货品名称',
                    align: "center",
                    dataIndex: 'lastTimeUnloadingGoodsName3'
                },
                {
                    title: '前三载卸货日期',
                    align: "center",
                    dataIndex: 'lastTimeUnloadingDate3',
                    customRender: function (t, r, index) {
                        return t ? t.substring(0, 10) : "";
                    }
                },
                {
                    title: '三次卸货照片',
                    align: "center",
                    dataIndex: 'lastTimeUnloadingPhotos',
                    scopedSlots: { customRender: 'imgSlot' }
                },
                {
                    title: '前三载证明文件',
                    align: "center",
                    dataIndex: 'documentation',
                    scopedSlots: { customRender: 'imgSlot' }
                },
                {
                    title: '上次清洗时间',
                    align: "center",
                    dataIndex: 'lastTimeCleaningDate',
                    customRender: function (t, r, index) {
                        return t ? t.substring(0, 10) : "";
                    }
                },
                {
                    title: '上次清洗证明',
                    align: "center",
                    dataIndex: 'lastTimeCleaningPhotos',
                    scopedSlots: { customRender: 'imgSlot' }
                },
                {
                    title: '入场时间',
                    align: "center",
                    dataIndex: 'entryTime'
                },
                {
                    title: '入场照片',
                    align: "center",
                    dataIndex: 'entryPic',
                    scopedSlots: { customRender: 'imgSlot' }
                },
                {
                    title: '出场时间',
                    align: "center",
                    dataIndex: 'exitTime'
                },
                {
                    title: '出场照片',
                    align: "center",
                    dataIndex: 'exitPic',
                    scopedSlots: { customRender: 'imgSlot' }
                },
                {
                    title: '随车装运记录表',
                    align: "center",
                    dataIndex: 'onboardRecordForm',
                    scopedSlots: { customRender: 'imgSlot' }
                },
                {
                    title: '登记时间',
                    align: "center",
                    dataIndex: 'registerDate'
                },
                {
                    title: '审核时间',
                    align: "center",
                    dataIndex: 'auditDate'
                },
                {
                    title: '检验时间',
                    align: "center",
                    dataIndex: 'surveyorDate'
                },
                {
                    title: 'gps截图',
                    align: "center",
                    dataIndex: 'screenshot',
                    scopedSlots: { customRender: 'imgSlot' }
                },
                {
                    title: '操作',
                    dataIndex: 'action',
                    align: "center",
                    fixed: "right",
                    width: 147,
                    scopedSlots: { customRender: 'action' }
                }
            ],
            url: {
                list: "/tankerRegistration/tankerRegistration/list?auditStatus_MultiString=11,16",
                edit: "/tankerRegistration/tankerRegistration/edit",
                delete: "/tankerRegistration/tankerRegistration/delete",
                deleteBatch: "/tankerRegistration/tankerRegistration/deleteBatch",
                exportXlsUrl: "/tankerRegistration/tankerRegistration/exportXls",
                importExcelUrl: "tankerRegistration/tankerRegistration/importExcel",
            },
            dictOptions: {},
            superFieldList: [],
            weight: '',
            receiptCompany: '',
        }
    },
    created() {
        this.getSuperFieldList();
    },
    computed: {
        importExcelUrl: function () {
            return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
        },
    },
    methods: {
        showModal(record) {
            this.tankerRegistration = record
            this.visible = true;
        },
        handleOk() {
            if (!this.weight.trim() || !this.receiptCompany.trim()) {
                this.$message.warning('请填写完整信息')
                return
            }
            this.confirmLoading = true;
            this.tankerRegistration.weight = this.weight
            this.tankerRegistration.receiptCompany = this.receiptCompany
            this.tankerRegistration.auditStatus = 16
            putAction(this.url.edit, this.tankerRegistration).then((res) => {
                if (res.success) {
                    this.$message.success(res.message)
                    this.visible = false;
                    this.confirmLoading = false;
                    this.weight = ''
                    this.receiptCompany = ''
                    this.loadData()
                } else {
                    this.$message.warning(res.message)
                    this.confirmLoading = false;
                }
            })
        },
        handleCancel(e) {
            console.log('Clicked cancel button');
            this.visible = false;
        },
        initDictConfig() {
        },
        getSuperFieldList() {
            let fieldList = [];
            fieldList.push({ type: 'string', value: 'plateNo', text: '车牌号', dictCode: '' })
            fieldList.push({ type: 'string', value: 'driverName', text: '司机姓名', dictCode: '' })
            fieldList.push({ type: 'string', value: 'phoneNum', text: '手机号', dictCode: '' })
            fieldList.push({ type: 'string', value: 'fleet', text: '车队', dictCode: '' })
            fieldList.push({ type: 'int', value: 'isEdibleOilLabel', text: '是否有食用油专用标签', dictCode: '' })
            fieldList.push({ type: 'string', value: 'lastTimeUnloadingLocation', text: '上次卸货地点', dictCode: '' })
            fieldList.push({ type: 'string', value: 'lastTimeUnloadingCompanyName', text: '上次装卸货公司名称', dictCode: '' })
            fieldList.push({ type: 'string', value: 'lastTimeUnloadingGoodsName', text: '上次装车货品名称', dictCode: '' })
            fieldList.push({ type: 'datetime', value: 'lastTimeUnloadingDate', text: '上次装卸货日期时间' })
            fieldList.push({ type: 'string', value: 'lastTimeUnloadingPhotos', text: '上次卸货照片', dictCode: '' })
            fieldList.push({ type: 'datetime', value: 'lastTimeCleaningDate', text: '上次清洗时间' })
            fieldList.push({ type: 'string', value: 'lastTimeCleaningPhotos', text: '上次清洗照片', dictCode: '' })
            fieldList.push({ type: 'int', value: 'auditStatus', text: '审核状态', dictCode: '' })
            fieldList.push({ type: 'int', value: 'entryStatus', text: '入场状态', dictCode: '' })
            fieldList.push({ type: 'datetime', value: 'entryTime', text: '入场时间' })
            fieldList.push({ type: 'string', value: 'entryPic', text: '入场照片', dictCode: '' })
            fieldList.push({ type: 'datetime', value: 'exitTime', text: '出场时间' })
            fieldList.push({ type: 'string', value: 'exitPic', text: '出场照片', dictCode: '' })
            fieldList.push({ type: 'string', value: 'vehicle45Photo', text: '车辆正面斜45度照片', dictCode: '' })
            fieldList.push({ type: 'string', value: 'tankPhoto', text: '罐内照片', dictCode: '' })
            fieldList.push({ type: 'string', value: 'oilDischargePortPhoto', text: '卸油口照片', dictCode: '' })
            fieldList.push({ type: 'int', value: 'isOdor', text: '是否异味 ', dictCode: '' })
            fieldList.push({ type: 'datetime', value: 'auditDate', text: '审核时间' })
            fieldList.push({ type: 'string', value: 'surveyorName', text: '检验人员姓名', dictCode: '' })
            fieldList.push({ type: 'datetime', value: 'surveyorDate', text: '检验时间' })
            this.superFieldList = fieldList
        },
    }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>